package com.dunshan.dunshanfile.controller;

import lombok.extern.log4j.Log4j2;
import org.slf4j.MDC;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;

/**
 * @author .dunshan
 * @program: dunshan-pef
 * @description: mdc 演示
 * @date 2021-11-14 10:19:07
 */
@Log4j2
@Controller
public class MdcDomeController {

    @GetMapping("/mdc/{id}")
    @ResponseBody
    public Object MdcGet(@PathVariable Integer id) {
        HashMap<String, Object> response = new HashMap<>();
        response.put("mdc", "调试");
        response.put("time", new Date());
        if (id == 1) {
            MDC.put("dunshan", "flag");
            log.info("日志写入 " + id);
            MDC.remove("dunshan");
        } else {
            log.info("不是 mdc 日志 " + id);
        }
        return response;
    }
}
